package com.zh.freechat.web;

import com.zh.freechat.domain.notice.SseEmitterServer;
import com.zh.webcommon.common.auth.annotation.NonePermission;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

/**
 * SseEmitter demo2
 */
@AllArgsConstructor
@Slf4j
@RestController
@RequestMapping("/sse")
public class SseEmitterController {
    private SseEmitterServer sseEmitterServer;

    /**
     * 创建连接
     */
    @NonePermission
    @GetMapping("/connect/{userId}")
    public SseEmitter connect(@PathVariable String userId) {
        log.debug("sse connect... user[{}]", userId);
        return sseEmitterServer.connect(userId);
    }

}

